JavaScript SDK
Connect to HyperBEAM processes using the @permaweb/aoconnect JavaScript library for web and Node.js applications.
Prerequisites
Node.js environment
@permaweb/aoconnectlibraryThe latest version of aos
Wallet file (
wallet.json) containing your cryptographic keysA HyperBEAM node running with the genesis_wasm profile
bashrebar3 as genesis_wasm shellThe Process ID for a process created with genesis_wasm (this is the default in the latest version of aos).
Step 1: Environment Setup
Install necessary dependencies:
npm install @permaweb/aoconnectEnsure your wallet file (wallet.json) is correctly formatted and placed in your project directory.
INFO
You can create a test wallet using this command: npx -y @permaweb/wallet > wallet.json
Step 2: Establish Connection
Create a new JavaScript file (e.g., index.js) and set up your Permaweb connection. You will need a processId of a process that you want to interact with.
import { connect, createSigner } from "@permaweb/aoconnect";
import fs from "node:fs";
const jwk = JSON.parse(fs.readFileSync("wallet.json", "utf-8"));
// The Process ID to interact with
const processId = "<your genesis_wasm generated process id>";
const { request } = connect({
MODE: "mainnet",
URL: "http://localhost:8734",
signer: createSigner(jwk),
});Step 3: Pushing a Message to a Process
Use the request function to send a message to the process. In aoconnect, this is done by using the push path parameter.
const processResult = await request({
path: `/${processId}~process@1.0/push/serialize~json@1.0`,
method: "POST",
target: processId,
signingFormat: "ANS-104",
});
console.log(processResult);Full Example
To run the full script, combine the snippets from Step 2 and 3 into index.js:
import { connect, createSigner } from "@permaweb/aoconnect";
import fs from "node:fs";
const jwk = JSON.parse(fs.readFileSync("wallet.json", "utf-8"));
const processId = "<your genesis_wasm generated process id>";
const { request } = connect({
MODE: "mainnet",
URL: "http://localhost:8734",
signer: createSigner(jwk),
});
const processResult = await request({
path: `/${processId}~process@1.0/push/serialize~json@1.0`,
method: "POST",
target: processId,
signingFormat: "ANS-104",
});
console.log(processResult);Now, run it:
node index.jsYou should see an object logged to the console, containing the ID of the message that was sent.
Conclusion
Following these steps, you've successfully sent a message to a process. This is a fundamental interaction for building applications on hyperAOS.